package cn.ecnu.search.model;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.DateFormat;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import java.time.LocalDateTime;
import java.util.List;


@Data
@Document(indexName = "paper", createIndex = true)
public class PaperModel {

    @Id
    private Integer paperId;

    @Field(type = FieldType.Text)
    private String title;

    @Field(type = FieldType.Keyword)
    private String journal;

    // 因为JSON序列化的关系所以要加JSON注解
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Field(type = FieldType.Date, format = DateFormat.date_hour_minute_second, pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime publishTime;

    @Field(type = FieldType.Text)
    private String link;

    @Field(type = FieldType.Text)
    private String abstracts;

    @Field(type = FieldType.Keyword) // 表示是固定的
    private String type;

    @Field(type = FieldType.Keyword)
    private Integer posterId;

    @Field(type = FieldType.Keyword)
    private String posterName;

    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Field(type = FieldType.Date, format = DateFormat.date_hour_minute_second, pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime postTime;

    @Field(type = FieldType.Nested)
    private List<AuthorModel> authors;

    @Field(type = FieldType.Nested)
    private List<FieldModel> fields;

    @Field(type = FieldType.Integer)
    private Integer noteNum;
}
